"use strict";
cc._RFpush(module, 'df1ebIVRedAoIKzVgvOLH5l', 'Controller');
// scripts\Controller.js

var Game = require('Game');
var Types = require('Types');
cc.Class({
    'extends': cc.Component,

    properties: {
        pressDirection: 0
    },

    // use this for initialization
    onLoad: function onLoad() {
        //this.physicsControlCube = Game.instance.physicsControlCube;
        //var gameArea = Game.instance.physicsControlCube;

        this.node.on(cc.Node.EventType.TOUCH_START, function (event) {
            //cc.director.loadScene('GameScene');
            this.updateTime = 0;
            this.tick = 0;
            this.isPress = true;
            var cube = Game.instance.physicsControlCube.getComponent('Cube');
            ///cube.onLeft();
            switch (this.pressDirection) {
                case Types.Direction.Left:
                    cube.onLeft();
                    break;
                case Types.Direction.Right:
                    cube.onRight();
                    break;
                case Types.Direction.Down:
                    cube.onRapidDownStart();
                    break;
                case Types.Direction.Up:
                    cube.onChangeDirection();
                    break;
            }
        }, this);
        this.node.on(cc.Node.EventType.TOUCH_END, function (event) {
            //cc.director.loadScene('GameScene');
            var cube = Game.instance.physicsControlCube.getComponent('Cube');
            switch (this.pressDirection) {
                case Types.Direction.Down:
                    cube.onRapidDownEnd();
                    break;
            }
            this.isPress = false;
        }, this);
    },

    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {
    update: function update(dt) {
        this.tick += dt;

        if (this.isPress && this.tick > 0.5) {
            var cube = Game.instance.physicsControlCube.getComponent('Cube');
            switch (this.pressDirection) {
                case Types.Direction.Left:
                    cube.onLeft();
                    break;
                case Types.Direction.Right:
                    cube.onRight();
                    break;
            }
        }
        this.updateTime += 1;
    }
});

cc._RFpop();